class Solution {
public:
    #寻找数组的中心索引
    int pivotIndex(vector<int>& nums) {
        int suml=0,sum=0;
        for(int x:nums) sum+=x;
        for(int i=0;i<nums.size();i++)
        {
            if(sum-suml-nums[i]==suml) return i;
            suml+=nums[i];
        }
        return -1;
    }

    #搜索插入位置
    int searchInsert(vector<int>& nums, int target) {
        int left=0,right=nums.size()-1,mid=(right-left)/2;
        while(right>=left){
            if(nums[mid]==target) return mid;
            else if(nums[mid]>target){
                right=mid-1;
                mid=left+(right-left)/2;
            }
            else if(nums[mid]<target){
                left=mid+1;
                mid=left+(right-left)/2;
            }
        }
        return left;
    }
    
    #合并区间
    vector<vector<int>> merge(vector<vector<int>>& intervals) {
        vector<vector<int>> V;
        sort(intervals.begin(), intervals.end());
        for(int i=0;i<intervals.size();i++){
            int L=intervals[i][0],R=intervals[i][1];
            if(!V.size()||V.back()[1]<L){
                V.push_back({L,R});
            }
            else{
                V.back()[1]=max(R,V.back()[1]);
            }
        }
        return V;
    }
};